import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_base/base/toolbar_view.dart';
import 'package:flutter_base/net/utils/BaseNetWork.dart';
import 'package:flutter_base/utils/ex.dart';

import 'loading_view.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class BaseContainer extends StatefulWidget {
  final Widget child;
  final Widget floatingActionButton;
  final Widget icon; //左侧按钮
  final Widget rightIcon; //右侧按钮
  final String title; //标题
  final BoxDecoration decoration; //背景样式
  final Color toolbarBgColor; //toolbar背景色
  final Color statusBgColor; //statusBar背景色
  final Function backIconPress; //toolbar 左边点击事件
  final Function rightIconPress; //toolbar 右边点击事件
  final bool showToolBar; //是否显示toolbar
  final bool statusDarkColor; //statusBar字体颜色 true 黑色 false 白色
  final double titleSize; //标题字体大小
  final double toolbarHeight; //toolbar高度
  final bool rightIconShow; //右侧按钮是否显示

  final Color titleColor; //标题字体颜色
  final EdgeInsets margin; //margin
  BaseContainer({
    Key key,
    this.child,
    this.floatingActionButton,
    this.backIconPress,
    this.rightIconPress,
    this.decoration,
    this.statusDarkColor = true,
    this.showToolBar = false,
    this.rightIconShow = false,
    this.title = "",
    this.titleSize = 0,
    this.toolbarHeight,
    this.toolbarBgColor = Colors.transparent,
    this.statusBgColor = Colors.transparent,
    this.titleColor = Colors.black,
    this.icon = const Icon(Icons.arrow_back_rounded),
    this.rightIcon,
    this.margin,
  }) : super(key: key);

  @override
  _BaseContainerState createState() => _BaseContainerState();
}

class _BaseContainerState extends State<BaseContainer> {
  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion(
      value: widget.statusDarkColor
          ? SystemUiOverlayStyle.dark
          : SystemUiOverlayStyle.light,
      child: Scaffold(
        body: Container(
          margin: widget.margin,
          decoration: widget.decoration,
          child: Stack(
            children: [
              Padding(
                  padding: EdgeInsets.only(
                    top: widget.showToolBar
                        ? getStatusBarHeight() + widget.toolbarHeight
                        : 0.0,
                  ),
                  child: widget.child),
              widget.showToolBar
                  ? Toolbar(
                      rightIconShow: widget.rightIconShow,
                      toolbarBgColor: widget.toolbarBgColor,
                      toolbarHeight: widget.toolbarHeight,
                      backIconPress: widget.backIconPress,
                      rightIconPress: widget.rightIconPress,
                      icon: widget.icon,
                      rightIcon: widget.rightIcon,
                      title: widget.title,
                      titleColor: widget.titleColor,
                      titleSize: widget.titleSize,
                      statusBgColor: widget.statusBgColor,
                    )
                  : SizedBox(),
            ],
          ),
        ),
        floatingActionButton: widget.floatingActionButton,
      ),
    );
  }
}
